﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml.Navigation;
using douban.Core.Apis;

namespace douban.Core.ViewModels
{
    public class CommentVm:VmBase
    {
        private Topic _thisTopic;
        public CommentVm()
        {
            TopicComments = new IncrementalLoadingCollection<Comment>(LoadMoreComments);
            //HotComments = new IncrementalLoadingCollection<Comment>();
        }

        private async Task<Tuple<IEnumerable<Comment>, bool>> LoadMoreComments(int start, int count)
        {
            var comments = await Api.GpSearchTopicComments(_thisTopic?.Id, start, count);

            return await Task.Run(() => Tuple.Create(comments, comments.Any()));
        }

        public IncrementalLoadingCollection<Comment> TopicComments { get; set; }
        //public IncrementalLoadingCollection<Comment> HotComments { get; set; }


        public override void OnNavigatedTo(NavigationEventArgs e)
        {
            _thisTopic = e.Parameter as Topic;
            TopicComments.Clear();
        }

        public override void OnNavigatedFrom(NavigationEventArgs e)
        {
            
        }
    }
}
